// ajax.js这个文件是我封装的数据请求模块,此项目中所有的数据请求都在此文件中执行

// 导入我二次封装的请求插件
import http from "./http"

// 定义ajax请求的基础路径 (配置环境变量) 在http中已封装
// 不同环境需要不同服务器基础地址 可以通过procss.env.NODE_ENV获取当前运行环境
console.log(process.env.NODE_ENV); // development 开发环境
// 生产环境production: npm run build 切换到生产环境 生产环境不需要走代理服务器。
// 开发环境development: npm run serve默认在开发环境下运行项目的,走代理服务器 
// let baseUrl;
// if(process.env.NODE_ENV == "development"){
//     baseUrl = "/Shop"  // 开发环境的代理路径
// }else{
//     baseUrl = "https://lianghj.top:8888/api/private/v1"  // 生产环境的原始路径 (项目打包时用这个路径)
// }


// 登录
var postLogin = params => http.post('/login', params);

// 根据 ID 查询用户信息
var getUserInfo = params => http.get('/users/' + params.id)

// 左侧菜单列表
var getMenus = () => http.get("/menus")

// 获取用户菜单
var getUsers = (params) => http.get(`/users?pagenum=${params.pagenum}&pagesize=${params.pagesize}`)

// 添加用户
var sesUsers = params => http.post('/users', params);

// 查找用户
var findUsers = params => http.get(`/users/${params.id}`, params)

// 删除用户
var deleteUsers = params => http.delete(`/users/${params.id}`, params)

// 修改用户信息
var getUserse = params => http.put(`/users/${params.id}`, params)

// 修改用户状态
var getType = params => http.put(`/users/${params.uId}/state/${params.type}`, params)

// 分配用户角色
var putUserRole = params => http.put(`/users/${params.id}/role`, params)

// 权限列表
var putRightslist = params => http.get(`/rights/${params.type}`, params)

// 角色列表
var UserRoleList = () => http.get("/roles")

// 添加角色
var AddRoleset = params => http.post(`/roles?roleName=${params.roleName}&roleDesc=${params.roleDesc}`, params)

// 编辑角色
var UserRoleset = params => http.put(`/roles/${params.id}`, params)

// 删除角色
var deleteleset = params => http.delete(`/roles/${params.id}`, params)

// 给角色分配权限
const postRoleRights = params => http.post(`/roles/${params.roleId}/rights`,params);

// 删除角色指定权限
const deleteRightRole = params => http.delete(`/roles/${params.roleId}/rights/${params.rightId}`);

// 商品列表
var goodList = params => http.get(`/goods?pagenum=${params.pagenum}&pagesize=${params.pagesize}`)

// 搜索商品
var GetGoods = params => http.get(`/goods/${params.id}`, params)

// 删除商品
var deleteGoods = params => http.delete(`/goods/${params.id}`, params)

// 商品分类数据列表
var categoriesList = ()=> http.get(`/categories`)

// 商品分类分页
var categoriesListse = params => http.get(`/categories?pagenum=${params.pagenum}&pagesize=${params.pagesize}`)

// 添加分类
var categoriesAdd = params => http.get(`/categories?cat_pid=${params.id}&cat_name=${params.cat_name}&cat_level=${params.cat_level}`)

// 编辑分类
var getCategor = params => http.put(`/categories/id=${params.id}&cat_name=${params.cat_name}`)

// 删除分类
const deleteCategor = params => http.delete(`/categories/${params.id}`,params);



var categoriesLists = params=> http.get(`/categories/${params.id}/attributes`,params)

// 订单列表
var ordersList = params => http.get(`/orders?pagenum=${params.pagenum}&pagesize=${params.pagesize}`)

// 搜索订单
var Getorders = params => http.get(`/orders/${params.id}`, params)

// 基于时间统计的折线图
var reportsType= () => http.get("/reports/type/1")


export {
    postLogin,
    goodList,
    deleteGoods,
    getMenus,
    getUsers,
    sesUsers,
    findUsers,
    getUserse,
    getType,
    deleteUsers,
    getUserInfo,
    putUserRole,
    UserRoleList,
    AddRoleset,
    UserRoleset,
    deleteleset,
    putRightslist,
    postRoleRights,
    deleteRightRole,
    GetGoods,
    Getorders,
    ordersList,
    categoriesList,
    categoriesLists,
    categoriesListse,
    deleteCategor,
    categoriesAdd,
    getCategor,
    reportsType
}
